package pers.qianyu.month_202012.date_20201227.dp_bag;

import java.util.*;

import static java.lang.Math.*;

/**
 * 3. 完全背包问题
 *
 * @author mizzle rain
 * @date 2020-12-27 20:41
 */
public class BagComplete {
    private int N;
    private int V;
    // 体积
    private int[] v;
    // 价值
    private int[] w;

    public void input() {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        N = Integer.parseInt(line[0]);
        V = Integer.parseInt(line[1]);
        v = new int[N];
        w = new int[N];
        for (int i = 0; i < N; i++) {
            v[i] = sc.nextInt();
            w[i] = sc.nextInt();
        }
        sc.close();
    }

    //public int solve() {
    //    int[][] dp = new int[N + 1][V + 1];
    //    for (int i = 1; i <= N; i++) {
    //        for (int j = 1; j <= V; j++) {
    //            if (j >= v[i - 1]) {
    //                dp[i][j] = max(dp[i - 1][j], dp[i][j - v[i - 1]] + w[i - 1]);
    //            } else {
    //                dp[i][j] = dp[i - 1][j];
    //            }
    //        }
    //    }
    //    return dp[N][V];
    //}

    public int solve() {
        int[] dp = new int[V + 1];
        for (int i = 1; i <= N; i++) {
            for (int j = v[i - 1]; j <= V; j++) {
                dp[j] = max(dp[j], dp[j - v[i - 1]] + w[i - 1]);
            }
            //ArrayUtil.printArrayAsMarkdownTable(v[i - 1], dp);
        }
        return dp[V];
    }

    public static void main(String[] args) {
        BagComplete bag = new BagComplete();
        bag.input();
        int result = bag.solve();
        System.out.println(result);
    }
}
